package cz.gelion.shylock.invoice.entity

import scala.beans.BeanProperty
import javax.persistence.Id
import javax.persistence.OneToMany
import javax.persistence.JoinColumn
import javax.persistence.Entity
import javax.persistence.Table
import cz.gelion.shylock.invoice.ManagedInfo
import javax.persistence.Column
import javax.persistence.ManyToOne
import javax.persistence.Temporal
import javax.persistence.TemporalType
import java.util.Calendar
import java.io.Serializable
import javax.persistence.EmbeddedId
import javax.persistence.PrePersist
import javax.persistence.PreUpdate


@Entity
@Table(name="invoice_manager", schema="invoice")
class InvoiceManager(p:InvoiceManager.PK) extends ManagedInfo {

  def this() = this(null)
  
  @EmbeddedId
  @BeanProperty
  var id:InvoiceManager.PK = p
  
  @BeanProperty
  @ManyToOne
  @JoinColumn(name="muser")
  var manager:Manager = _
  
  
  @BeanProperty
  @Column(name="mtime")
  @Temporal(TemporalType.TIMESTAMP)
  var mtime:Calendar = _
  
  @PrePersist
  @PreUpdate
  def update = stamp

  
}

object InvoiceManager {
  class PK(i:Manager, s:SubjectUnit)	 extends Serializable {
    
    
	  @BeanProperty
	  @ManyToOne
	  @JoinColumn(name="issuer")
	  var issuer:Manager = i
	  
	  @BeanProperty
	  @ManyToOne
	  @JoinColumn(name="subject_unit")
	  var subjectUnit:SubjectUnit = s
		  
		 
		  
	  def this() = this(null,null)
    
  }
  
}